package com.example.www.jiguvideo.module.service;

import com.example.www.jiguvideo.module.entity.Video;
import com.example.www.jiguvideo.module.mapper.VideoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;


@Service
public class VideoService {

    @Resource
    private VideoMapper mapper;

    public Video getVideoInfoById(BigInteger id) {


            return mapper.getById(id);
    }

    public List<Video> getAllVideoInfo() {
        return mapper.getAll();
    }


    public int createVideo(String name, String image, String introduce,
                           String pictures, String actor, String particular, String photo) {

        int timestamp = (int) (System.currentTimeMillis() / 1000);


        Video video1 = new Video();
        video1.setName(name);
        video1.setImage(image);
        video1.setIntroduce(introduce);
        video1.setPictures(pictures);
        video1.setActor(actor);
        video1.setParticular(particular);
        video1.setPhoto(photo);
        video1.setCreateTime(timestamp);
        video1.setUpdateTime(timestamp);
        video1.setIsDeleted(0);

        return mapper.insert(video1);
    }


    public int updateVideo(BigInteger videoId, String name, String image, String introduce,
                           String pictures, String actor, String particular, String photo) {

        int timestamp = (int) (System.currentTimeMillis() / 1000);


        Video video = new Video();
        video.setId(videoId);
        video.setName(name);
        video.setImage(image);
        video.setIntroduce(introduce);
        video.setPictures(pictures);
        video.setActor(actor);
        video.setParticular(particular);
        video.setPhoto(photo);
        video.setUpdateTime(timestamp);

        
        return mapper.update(video);
    }


    public int deleteVideo(BigInteger id) {
        return mapper.delete(id, (int) (System.currentTimeMillis() / 1000));
    }


}
